package com.rockcent.mall.lib.repository;

import com.rockcent.common.domain.enumclass.Whether;
import com.rockcent.mall.lib.domain.MerchantOrder;
import com.rockcent.mall.lib.domain.enumclass.*;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by oyhk on 14-6-22.
 */
@Repository
public interface MerchantOrderRepository extends JpaRepository<MerchantOrder, Long>, JpaSpecificationExecutor, MerchantOrderRepositoryCustom {
    /**
     * @param mallOrderId
     * @param mallId
     * @return
     */
    List<MerchantOrder> findByMallOrderIdAndMallId(Long mallOrderId, Long mallId);

    /**
     * @param id
     * @param id1
     * @return
     */
    MerchantOrder findByIdAndMerchantId(Long id, Long id1);

    /**
     * @param marketOrderNum
     * @param merchantRole
     * @return
     */
    MerchantOrder findByMarketOrderNumAndMerchantRole(String marketOrderNum, MerchantOrderMerchantRole merchantRole);

    /**
     * @param mallOrderNum
     * @return
     */
    List<MerchantOrder> findByMallOrderNum(String mallOrderNum);

    /**
     * @param merchantOrderNum
     * @param mallId
     * @return
     */
    MerchantOrder findByOrderNumAndMallId(String merchantOrderNum, Long mallId);

    /**
     * @param marketOrderNum
     * @param merchantRole
     * @param sourceType
     * @return
     */
    MerchantOrder findByMarketOrderNumAndMerchantRoleAndSourceType(String marketOrderNum, MerchantOrderMerchantRole merchantRole, MerchantOrderSourceType sourceType);

    /**
     * @param id
     * @param mallId
     * @return
     */
    MerchantOrder findByIdAndMallId(Long id, Long mallId);

    /**
     * @param mallOrderNumList
     * @param no
     * @param supplier
     * @return
     */
    List<MerchantOrder> findByMallOrderNumInAndIsDeleteAndMerchantRoleNot(List<String> mallOrderNumList, Whether no, MerchantOrderMerchantRole supplier);

    /**
     * @param orderNum
     * @param id
     * @param id1
     * @return
     */
    MerchantOrder findByOrderNumAndMerchantIdAndMallId(String orderNum, Long id, Long id1);

    /**
     * @param orderNum
     * @param no
     * @param supplier
     * @return
     */
    List<MerchantOrder> findByMallOrderNumAndIsDeleteAndMerchantRoleNot(String orderNum, Whether no, MerchantOrderMerchantRole supplier);

    /**
     * @param mallOrderId
     * @return
     */
    List<MerchantOrder> findByMallOrderId(Long mallOrderId);

    /**
     * @param id
     * @param goods
     * @param shipped
     * @param aDefault
     * @param no
     * @param supplier
     * @return
     */
    Integer countByCustomerIdAndOrderTypeAndStatusAndEvaluateStatusAndIsDeleteAndMerchantRoleNot(Long id, OrderType goods, OrderStatus shipped, EvaluateStatus aDefault, Whether no, MerchantOrderMerchantRole supplier);

    /**
     * @param logisticsNumber
     * @param logisticsId
     * @return
     */
    MerchantOrder findByLogisticsNumberAndLogisticsId(String logisticsNumber, Long logisticsId);

    /**
     * @param marketOrderNum
     * @param merchantRole
     * @return
     */
    MerchantOrder findTop1ByMarketOrderNumAndMerchantRole(String marketOrderNum, MerchantOrderMerchantRole merchantRole);
}
